🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / feature / widget / src / main / kotlin / org / meshtastic / feature / widget / WidgetResourceEnvironment.kt
Displaying Raw • Download
feature/widget/src/main/kotlin/org/meshtastic/feature/widget/WidgetResourceEnvironment.kt 65a1f5ce4d0e4b8eafcd0bbfccafd41dc6ee888a (65a1f5ce) Text, 3.27 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.widget
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.CompositionLocalProvider
Tff7b72import T7ee787androidx.compose.ui.platform.LocalConfiguration
Tff7b72import T7ee787androidx.compose.ui.platform.LocalDensity
Tff7b72import T7ee787androidx.compose.ui.unit.Density
Tff7b72import T7ee787androidx.glance.LocalContext
T8b949e/**
* Makes Compose Multiplatform resources usable inside a Glance composition.
*
* Glance runs its own composition with its own set of composition locals ([androidx.glance.LocalContext],
* [androidx.glance.LocalSize], ...). It deliberately does *not* provide the `androidx.compose.ui` locals, because a
* Glance tree is translated to `RemoteViews` rather than laid out and drawn by Compose UI.
*
* Compose Multiplatform's `stringResource` does not know that. On Android it reads
* [androidx.compose.ui.platform.LocalContext] to find the asset loader, plus [LocalConfiguration] to pick the locale
* and [LocalDensity] to pick density-qualified resources. None of those are present in a Glance composition, so any
* `stringResource` call inside a widget throws `CompositionLocal ... not present` unless we bridge them across.
*
* That is what this composable does, and it is the only reason it exists. Wrapping widget content in it is therefore
* mandatory, not optional: the widget is fully translated via Crowdin (`core/resources`), so essentially every visible
* string depends on this bridge.
*
* Two consequences worth knowing before changing this:
* - The bridge is a workaround, not a documented Glance pattern. If Compose Multiplatform starts reading another
* composition local when resolving resources, every string in the widget begins throwing at runtime. That failure is
* caught by [LocalStatsWidget.onCompositionError] rather than crashing the app, and `LocalStatsWidgetContentTest`
* fails in CI if resolution breaks.
* - [LocalDensity] is derived from the display metrics rather than from Glance's `LocalSize`. Glance sizing is
* expressed in `dp` and converted during translation, so density only affects which resource qualifier is chosen here
* — it must not be used to compute widget layout.
*/
Tf0883e@Composable
Tff7b72internal Tff7b72fun Td2a8ffWidgetResourceEnvironmentTb4b4b4(Te6edf3contentTb4b4b4: Tf0883e@Composable Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3context Tff7b72= Te6edf3LocalContextTb4b4b4.Te6edf3current
Te6edf3CompositionLocalProviderTb4b4b4(
Te6edf3androidxTb4b4b4.Te6edf3composeTb4b4b4.Te6edf3uiTb4b4b4.Te6edf3platformTb4b4b4.Te6edf3LocalContext Te6edf3provides Te6edf3contextTb4b4b4,
Te6edf3LocalConfiguration Te6edf3provides Te6edf3contextTb4b4b4.Te6edf3resourcesTb4b4b4.Te6edf3configurationTb4b4b4,
Te6edf3LocalDensity Te6edf3provides Te6edf3DensityTb4b4b4(Te6edf3contextTb4b4b4.Te6edf3resourcesTb4b4b4.Te6edf3displayMetricsTb4b4b4.Te6edf3densityTb4b4b4)Tb4b4b4,
Te6edf3content Tff7b72= Te6edf3contentTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.09s